import service from '../../utils/request';
import mod from '../mod'

const payment = {
    list(pageSize, page, isPagi) {
        return service.get(mod.payment, {params: {per_page: pageSize, page: page, pagi: isPagi}})
            .then(data => {
                return Promise.resolve(data)
            }).catch(err => {
                return Promise.reject(err)
            })
    },
    newPayment(saleId) {
        return service.post(mod.payment + '?saleId=' + saleId)
            .then(data => {
                return Promise.resolve(data)
            }).catch(err => {
                return Promise.reject(err)
            })
    },
    makePayment(payment) {
        return service.put(mod.payment, payment)
            .then(data => {
                return Promise.resolve(data)
            }).catch(err => {
                return Promise.reject(err)
            })
    },
    suspendPayment(id) {
        return service.patch(mod.payment + '?id=' + id)
            .then(data => {
                return Promise.resolve(data)
            })
            .catch(err => {
                return Promise.reject(err)
            })
    },
    getPayment(id) {
        return service.get(mod.payment + '/get', {params: {id: id}})
            .then(data => {
                return Promise.resolve(data)
            })
            .catch(err => {
                return Promise.reject(err)
            })
    },
    calChange(payment) {
        return service.patch(mod.payment + '/calChange', payment)
            .then(data => {
                return Promise.resolve(data)
            }).catch(err => {
                return Promise.reject(err)
            })
    }
}

export default payment;